import requests
import re
import pyttsx3

class ttsx(object):
      def __init__(self,rate=-40):
          self.rate = rate
      def sayText(self,str):
          self.engine = pyttsx3.init()
         #语速
          rate = self.engine.getProperty('rate')
          self.engine.setProperty('rate', 300)

         #音量
         #volume = self.engine.getProperty('volume')
         #engine.setProperty('volume', volume - 0.25)

         #声音
         #voices = self.engine.getProperty('voices')
         #for voice in voices:
         #   self.engine.setProperty('voice', voice.id)
         #   print(voice.id)
          self.engine.say(str)
          self.engine.runAndWait()

ttx = ttsx()
ttx.__init__(20)

for number in range(512, 187275):
    full_url = "http://www.seobishop.com/ldks/19076/5153"+number.__str__()+".html"
    # full_url ="http://www.xbiqugeu.net/book/217/1098305.html"
    html = requests.get(full_url)

    html.encoding = 'utf-8'
    # html.encoding = 'gbk'
    pattern = re.compile(r'[^\u4e00-\u9fa5]')
    chinese = re.sub(pattern, "", html.text)
    # print(html.text)
    xxxxx = html.text.replace("<br><br>", "\n")
    xxxxx = xxxxx.replace("<br /><br />", "\n")
    xxxxx = xxxxx.replace("<br/><br/>", "\n")
    xxxxx = xxxxx.replace("</p><p>", "\n")
    xxxxx = xxxxx.replace("<br />　　<br />", "\n")

    xxxxx = xxxxx.replace("&nbsp;&nbsp;&nbsp;&nbsp;", "\t")

    # print(xxxxx)
    start = xxxxx.index("请耐心等待,并刷新页面")
    end = xxxxx.index("section-opt m-bottom-opt")
    zzzz = xxxxx[start:end]
    print(zzzz)

    start = zzzz.index("                 ")
    end = zzzz.index("<a href=\"javascript")
    zxdc = zzzz[start + 9:end]
    print(zxdc)

    xdf = html.text.index(">下一")
    print(xdf)
    print(html.text[xdf - 40:xdf])
    ttx.sayText(zxdc)
    #============================================================================================================================================================================
    full_url = "http://www.seobishop.com/ldks/19076/5153"+number.__str__()+"_2.html"
    # full_url ="http://www.xbiqugeu.net/book/217/1098305.html"
    html = requests.get(full_url)

    html.encoding = 'utf-8'
    # html.encoding = 'gbk'
    pattern = re.compile(r'[^\u4e00-\u9fa5]')
    chinese = re.sub(pattern, "", html.text)
    # print(html.text)
    xxxxx = html.text.replace("<br><br>", "\n")
    xxxxx = xxxxx.replace("<br /><br />", "\n")
    xxxxx = xxxxx.replace("<br/><br/>", "\n")
    xxxxx = xxxxx.replace("</p><p>", "\n")
    xxxxx = xxxxx.replace("<br />　　<br />", "\n")

    xxxxx = xxxxx.replace("&nbsp;&nbsp;&nbsp;&nbsp;", "\t")

    # print(xxxxx)
    start = xxxxx.index("请耐心等待,并刷新页面")
    end = xxxxx.index("section-opt m-bottom-opt")
    zzzz = xxxxx[start:end]
    print(zzzz)

    start = zzzz.index("                 ")
    end = zzzz.index("<a href=\"javascript")
    zxdc = zzzz[start + 9:end]
    print(zxdc)

    xdf = html.text.index(">下一")
    print(xdf)
    print(html.text[xdf - 40:xdf])
    ttx.sayText(zxdc)


#xxx = re.sub('[a-zA-Z0-9"#$%&()*+,-./:;<=>?@，。?★、…【】《》？“”‘！[\\]^_`{|}~\s]+', "", strr)


